import {UserActions} from './user';

const initialState = {
  chargeList: {
    count: 0,
    current: 0,
    total: 0,
    results: [],
  },
  chargeStat: {
    amt__sum: 0,
    plan__space__sum: 0,
    dentist_count: 0,
  },
};

export const ChargeActions = {
  CHARGE_UPDATE: 'charge_update',
};

export function updateCharge(payload) {
  return {
    type: ChargeActions.CHARGE_UPDATE,
    payload,
  };
}

export default function charge(state = initialState, action) {
  switch (action.type) {
    case ChargeActions.CHARGE_UPDATE:
      return {...state, ...action.payload};
    case UserActions.USER_SIGN_OUT:
      return {
        chargeList: {
          count: 0,
          current: 0,
          total: 0,
          results: [],
        },
        chargeStat: {
          amt__sum: 0,
          plan__space__sum: 0,
          dentist_count: 0,
        },
      };
    default:
      return state;
  }
}
